/**
 * @param {number} k
 * @param {number} x
 * @return {number}
 */
var findMaximumNumber = function(k, x) {
    const getRes = (n) => {
        let binaryStr = n.toString(2)
        let res = 0
        for(let i = 1; i <= binaryStr.length; i += k) {
            if(binaryStr.charAt(i - 1) == 1 && (binaryStr.length - i + 1) % x == 0) {
                res++
            }
        }
        return res
    }
    let num = 0, sum = 0
    while(sum <= k) {
        num++
        sum += getRes(num)
    }
    return num - 1
};
// console.log(findMaximumNumber(9, 1));
// console.log(findMaximumNumber(7, 2));
console.log(findMaximumNumber(3278539330613, 5));